/* This file is part of qjson
  *
  * Copyright (C) 2009 Till Adam <adam@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License version 2.1, as published by the Free Software Foundation.
  * 
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  *
  * -------------------------------------------------------------------------
  *
  * This version of the file has been modified from the original library. To
  * download the original library, go to http://qjson.sourceforge.net/
  *
  */

#ifndef BANGO_QJSON_SERIALIZER_H
#define BANGO_QJSON_SERIALIZER_H

#include <QList>

class QIODevice;
class QString;
class QVariant;
class QByteArray;

  /**
  * @brief Main class used to convert QVariant objects to JSON data.
  *
  * QVariant objects are converted to a string containing the JSON data.
  * If QVariant object is empty or not valid a <em>null</em> json object is returned.
  */

class Serializer {
  public:
    Serializer();
    ~Serializer();

    /**
    * @brief How the indentation should work.
    *
    * none (default) : { "foo" : 0, "foo1" : 1, "foo2" : [ { "foo3 : 3, "foo4" : 4 } ] }
    *
    * minimum : { "foo" : 0, "foo1" : 1, "foo2" : [
    *             { "foo3 : 3, "foo4" : 4 }
    *           ] }
    *
    * medium : {
    *           "foo" : 0, "foo1" : 1, "foo2" : [
    *            {
    *             "foo3 : 3, "foo4" : 4
    *            }
    *           ]
    *          }
    * full : {
    *         "foo" : 0,
    *         "foo1" : 1,
    *         "foo2" : [
    *          {
    *           "foo3 : 3,
    *           "foo4" : 4
    *          }
    *         ]
    *        }
    */
    enum IndentMode {
      IndentNone,
      IndentMinimum,
      IndentMedium,
      IndentFull
    };


    bool specialNumbersAllowed;
    IndentMode indentMode;
    QByteArray buildIndent(int spaces);
    QByteArray serialize( const QVariant &v, int reserved = 0);
    QString sanitizeString( QString str );

    QByteArray join( const QList<QByteArray>& list, const QByteArray& sep );

    /**
     * Allow or disallow writing of NaN and/or Infinity (as an extension to QJson)
     */
    void allowSpecialNumbers(bool allow);

    /**
     * Is Nan and/or Infinity allowed?
     */
    bool getSpecialNumbersAllowed() const;

    /**
     * set output indentation mode as defined in QJson::IndentMode
     */
    void setIndentMode(IndentMode mode = IndentNone);

    /**
     * Returns one of the indentation modes defined in QJson::IndentMode
     */
    IndentMode getIndentMode() const;

};

#endif // BANGO_QJSON_SERIALIZER_H
